<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>

    const properties = [
      "中华园,北京市,公寓",
      "华景苑,上海市,别墅",
      "新城市广场,深圳市,公寓",
      "雅居乐花园,广州市,别墅",
      "恒大城,广州市,公寓",
      "太阳花园,北京市,别墅"
    ];

    //数组中每一个元素(字符串)转化为数组
    //分别判断数组的每一项是公寓还是别墅  然后数组第一项 放到新数组中

    function fn(data) {

      const res = []

      let newArr = data.map(function (item) {
        let arr = item.split(',')
        return arr
        // console.log(arr);
      })
      console.log(newArr);
      // if(newArr.find())
      newArr.forEach(function ([houseName, , houseStyle]) {
        if (res[houseStyle]) {
          res[houseStyle].push(houseName)
        } else {
          res[houseStyle] = []
          res[houseStyle].push(houseName)
        }
      })


      console.log(res);
    }

    fn(properties)
  </script>
</body>

</html>